efform_onload = function ()
{

	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN10","query");
	efgrid_onRowClicked("ef_grid_r",0);
	$('#ef_region_detail').hide();
	$('#inqu_status-0-fdForeignId').val($('#fdForeignId').val());
}; 
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide(); 
		var grid = efgrid.getGridObject("ef_grid_d");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {}
};
button_query_onclick = function () 
{   	
	efgrid.submitInqu( "ef_grid_r", "ZM","ZMCN10","query");
}
button_update_onclick = function (){ 
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","update",true);
	//以下是行增，有校验
	var info = getSCZXEiInfos("ZMCN10","ef_grid_r");//ZMCN10 为EFFORM id，ef_grid_r为grid id（paintId）
	if (null != info) { 
		EiCommunicator.send("ZMCN10", "validate1", info, validate1_callback);
	}
}
button_insert_onclick = function (){
	if (isSelected("ef_grid_r") == 0)return; 
//	efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","insert",true);
	var info = getSCZXEiInfos("ZMCN10","ef_grid_r");
	if (null != info) { 
		EiCommunicator.send("ZMCN10", "validate", info, validate_callback);
	}
} 

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_r");
	if (grid == 0)return; 
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r){
			//删除主表时判断明细表有没有生效的记录，如果明细有生效的记录，不能删除或修改主表
			var info = getSCZXEiInfos("ZMCN10","ef_grid_r");
			if (null != info) { 
				EiCommunicator.send("ZMCN10", "validate1", info, validate1_callback);
			}
		}
	}); 
}

var fdForeignId,fdYear;
efgrid_onRowClicked = function( grid_id, row_index ){
	if(grid_id == "ef_grid_r"){ 
		$('#ef_region_detail').show();
		var grid = efgrid.getGridObject(grid_id);

		fdForeignId=grid.getCellValueByColumnName(row_index,"fdKeyId");
		fdYear=grid.getCellValueByColumnName(row_index,"fdYear");
		
		var info = new EiInfo();
 
		info.set("fdForeignId",fdForeignId); 
		info.set("fdYear",fdYear); 
 
	//	$('#fdYear').val(fdYear);

		$('#inqu_status-0-fdForeignId').val(fdForeignId);
	//	$('#inqu_status-0-fdYear').val(fdYear);
		EiCommunicator.send("ZMCN11", "query", info, ajax_callback);  
	}
	if(grid_id == "ef_grid_d"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_inqu1').find('#inqu_status1-0-'+colname).val(colvalue);
		} 
	}
}
var ajax_callback= {
		onSuccess: function(eiInfo) { 
			 efwindow.hide();
			 var grid = efgrid.getGridObject("ef_grid_d");
			 grid.refresh(eiInfo);
		},
		onFail:function(eMsg)
		{
			EFAlert("新增失败，原因："+eMsg); 
		}
	}
var validate1_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					//可以修改，然后再进行重复性校验
					EiCommunicator.send("ZMCN10", "validate", eiInfo, validate_callback);
				}else{
					$('#ef_region_detail').hide();
					//执行删除操作
					efgrid.submitForm( "ef_grid_r", "ZM","ZMCN10","delete",true);
				}
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
var validate_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_r");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE"){
					oper="update";
				}
				efgrid.submitForm("ef_grid_r", "ZM", "ZMCN10",oper, true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
var validate_detail_callback={
		onSuccess:function(eiInfo){
			if(eiInfo.getStatus()==-1){
				EFAlert("操作失败，原因："+eiInfo.getMsg());
			}else{
/*				 efwindow.hide();
				 var grid = efgrid.getGridObject("ef_grid_d");
				 grid.refresh(eiInfo);*/
				var oper="insert";
				if(eiInfo.get("efCurButtonEname")=="UPDATE1"){
					oper="update";
				}
				efgrid.submitForm( "ef_grid_d", "ZM","ZMCN11",oper,true);
			}
		},
		onFail:function(eMsg)
		{
			EFAlert("操作失败，原因："+eMsg); 
		}
}
/********************************************************************************
 ***********************************从表操作**************************************** 
 ********************************************************************************/
button_insert1_onclick = function (){
	//以下注释掉的内容为列表下方输入内容新增方式。
/*	var info = getDetail("ef_region_inqu1","inqu_status1");
	if (null != info) { 
		EiCommunicator.send("ZMCN11", "insert", info, ajax_callbackconfirm);
	} */
	//以下方式为行增
	if (isSelected("ef_grid_d") == 0)return; 
//	efgrid.submitForm( "ef_grid_d", "ZM","ZMCN10","insert1",true);
	//以下为行增有重复性校验
	var info = getSCZXEiInfos("ZMCN10","ef_grid_d");
	if (null != info) { 
		EiCommunicator.send("ZMCN11", "validate", info, validate_detail_callback);
	}
}
button_update1_onclick = function (){
	//以下注释掉的内容为列表下方输入内容新增方式。
/*	var info = getDetail("ef_region_inqu1","inqu_status1");
	if (null != info) {
		EiCommunicator.send("ZMCN11", "update", info, ajax_callbackconfirm);
	} */
	//以下方式为行修改无校验
	if (isSelected("ef_grid_d") == 0)return; 
//	efgrid.submitForm( "ef_grid_d", "ZM","ZMCN10","update1",true);
	var grid=isSelected("ef_grid_d");
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行修改！"); return;
		}
	}
	//以下为行修改有重复性校验
	var info = getSCZXEiInfos("ZMCN10","ef_grid_d");
	if (null != info) { 
		EiCommunicator.send("ZMCN11", "validate", info, validate_detail_callback);
	}
}
button_delete1_onclick = function (){
	var grid=isSelected("ef_grid_d");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN11","delete",true);
	}); 
}
	
	
	
//	var grid=isSelected("ef_grid_d");
//	if (grid == 0)return;  
//	EFConfirm('你确认要删除吗?', '确认框', function(r) {
//		if(r){
//			efgrid.submitForm( "ef_grid_d", "ZM","ZMCN11","delete",true);
//		}
//	}); 
//}  
button_report_onclick = function (){
	var grid=isSelected("ef_grid_d");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("该记录或有记录已经上报！"); return;
		}
	}
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_d", "ZM","ZMCN11","report",true);
	}); 
}
var ajax_callbackconfirm = {
	onSuccess : function(eiInfo) {

		var info = new EiInfo();

		info.set("fdForeignId",fdForeignId); 
		info.set("fdYear",fdYear); 

		$('#fdForeignId').val(fdForeignId);
		$('#fdYear').val(fdYear);

		$('#inqu_status1-0-fdForeignId').val(fdForeignId);
		$('#inqu_status1-0-fdYear').val(fdYear);
		EiCommunicator.send("ZMCN11", "query", info, ajax_callback);  
	}, 
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg);
	}
}
efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows();  
	if(grid_id=="ef_grid_d")
	{

	   
		for(var i = 0 ; i < rows.length;i++){
			grid.setCellValue(rows[i],0,"草拟",TYPE_DATA);
//			grid.setCellValue(rows[i],3,fdBjdw,TYPE_DATA);
		}
	}
}